import java.util.HashSet;
import java.util.List;
import java.util.Set;

class Matrix {
    private List<List<Integer>> matrixList;

    Matrix(List<List<Integer>> lists) {
        this.matrixList = lists;
    }

    Set<MatrixCoordinate> getSaddlePoints() {

        Set<MatrixCoordinate> results = new HashSet<>();

        for (int i = 0; i < this.matrixList.size(); i++)
            for (int j = 0; j < this.matrixList.get(i).size(); j++)
                if (this.isSaddlePoints(i, j)) results.add(new MatrixCoordinate(i, j));

        return results;
    }

    private boolean isSaddlePoints(final int rowIdx, final int colIdx) {
        int currentNumber = this.matrixList.get(rowIdx).get(colIdx);

        return this.isGreaterOrEqualInRow(currentNumber, rowIdx) && this.isLessOrEqualInColumn(currentNumber, colIdx);

    }

    private boolean isGreaterOrEqualInRow(final int number, final int rowIdx) {
        List<Integer> rowList = this.matrixList.get(rowIdx);

        for (int i : rowList) {
            if (i > number) return false;
        }

        return true;
    }

    private boolean isLessOrEqualInColumn(final int number, final int colIdx) {
        for (List<Integer> li : this.matrixList) {
            if (li.get(colIdx) < number) return false;
        }

        return true;
    }
}
